﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Recognition;
using System.Collections.ObjectModel;

namespace SmartVoice
{
    class VoiceRecognizer
    {        
        public SpeechRecognitionEngine speechReco = null;
        private List<string> grammarList = new List<string>();

        public VoiceRecognizer()
        {
            speechReco = new SpeechRecognitionEngine();
            speechReco.SetInputToDefaultAudioDevice();

        }

        public void RecognizeAsync()
        {
            speechReco.RecognizeAsync(RecognizeMode.Multiple);
        }

        public void RecognizeAsyncCancel()
        {
            speechReco.RecognizeAsyncCancel();
        }

        public void UnloadAllGrammars()
        {
            speechReco.UnloadAllGrammars();
        }

        public void SetGrammar(List<String> grammar)
        {
            for (int z = 0; z < grammar.Count; z++)
            {
                grammarList.Add(grammar[z]);
            }
            Choices voiceCommands = new Choices(grammarList.ToArray());
            GrammarBuilder builder = new GrammarBuilder(voiceCommands);
            Grammar gram = new Grammar(builder);
            speechReco.LoadGrammar(gram);
        }

        public void SetGlobalGrammar()
        {
            DictationGrammar global = new DictationGrammar();
            speechReco.LoadGrammar(global);
        }

    }
}
